﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using nERP.Model.Bas;
using nERP.Model;

namespace nERP.ViewModel.Bas.GoodsClassVMs
{
    public partial class GoodsClassListVM : BasePagedListVM<GoodsClass_View, GoodsClassSearcher>
    {
        
        protected override IEnumerable<IGridColumn<GoodsClass_View>> InitGridHeader()
        {
            return new List<GridColumn<GoodsClass_View>>{
                
                this.MakeGridHeader(x => x.GoodsClass_Name).SetTitle(@Localizer["Page.商品类别名称"].Value),
                this.MakeGridHeader(x => x.GoodsClass_Remark).SetTitle(@Localizer["_Admin.Remark"].Value),
                this.MakeGridHeader(x => x.GoodsClass_CreateTime).SetTitle(@Localizer["_Admin.CreateTime"].Value),
                this.MakeGridHeader(x => x.GoodsClass_UpdateTime).SetTitle(@Localizer["_Admin.UpdateTime"].Value),
                this.MakeGridHeader(x => x.GoodsClass_CreateBy).SetTitle(@Localizer["_Admin.CreateBy"].Value),
                this.MakeGridHeader(x => x.GoodsClass_UpdateBy).SetTitle(@Localizer["_Admin.UpdateBy"].Value),
                this.MakeGridHeader(x => x.GoodsClass_IsValid).SetTitle(@Localizer["_Admin.IsValid"].Value),

                this.MakeGridHeaderAction(width: 200)
            };
        }

        
        public override IOrderedQueryable<GoodsClass_View> GetSearchQuery()
        {
            var query = DC.Set<GoodsClass>()
                
                .CheckContain(Searcher.Name, x=>x.Name)
                .CheckContain(Searcher.Remark, x=>x.Remark)
                .CheckBetween(Searcher.CreateTime?.GetStartTime(), Searcher.CreateTime?.GetEndTime(), x => x.CreateTime, includeMax: false)
                .CheckBetween(Searcher.UpdateTime?.GetStartTime(), Searcher.UpdateTime?.GetEndTime(), x => x.UpdateTime, includeMax: false)
                .CheckContain(Searcher.CreateBy, x=>x.CreateBy)
                .CheckContain(Searcher.UpdateBy, x=>x.UpdateBy)
                .Select(x => new GoodsClass_View
                {
				    ID = x.ID,
                    
                    GoodsClass_Name = x.Name,
                    GoodsClass_Remark = x.Remark,
                    GoodsClass_CreateTime = x.CreateTime,
                    GoodsClass_UpdateTime = x.UpdateTime,
                    GoodsClass_CreateBy = x.CreateBy,
                    GoodsClass_UpdateBy = x.UpdateBy,
                    GoodsClass_IsValid = x.IsValid,
                })
                .OrderBy(x => x.ID);
            return query;
        }

        
    }
    public class GoodsClass_View: GoodsClass
    {
        
        public string GoodsClass_Name { get; set; }
        public string GoodsClass_Remark { get; set; }
        public DateTime? GoodsClass_CreateTime { get; set; }
        public DateTime? GoodsClass_UpdateTime { get; set; }
        public string GoodsClass_CreateBy { get; set; }
        public string GoodsClass_UpdateBy { get; set; }
        public bool GoodsClass_IsValid { get; set; }

    }

}